package ThreadPoolExecutors;

import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:34398
 * Date:2024-07-27
 * Time:9:03
 */
public class ExecutorUse {
    public static void main(String[] args) {

        //蛇者这个线程池固定只有4个线程
        ExecutorService service=Executors.newFixedThreadPool(4);


        for (int i = 0; i <1000 ; i++) {
            int id=i;
            Thread cur= Thread.currentThread();
            service.submit(()->{
                System.out.println("执行任务id："+id+"，"+cur.getName());
            });
        }

        //把线程池所有线程终止
        service.shutdown();
    }
}
